package org.example.controller;

import org.example.model.Book;
import org.springframework.web.bind.annotation.*;

//使用@RestController注解替换@Controller与@ResponseBody注解，简化书写
@RestController
@RequestMapping("/books")
public class BookController {

    /**
     *
     * 简化操作类型操作
     *
     * */
    @PostMapping
    public String save(@RequestBody Book book){
        System.out.println("book save..." + book);
        return "{'module':'book save'}";
    }


    //使用@DeleteMapping简化DELETE请求方法对应的映射配置
    @DeleteMapping("/{id}")
    public String delete(@PathVariable Integer id){
        System.out.println("delete save..." + id);
        return "{'module':'book save'}";
    }

    @DeleteMapping
    public String deleteDelel(){
        System.out.println("我是无参删除");
        return "{'module':'book save'}";
    }

    @GetMapping("/{id}")
    public String update(@PathVariable Integer id){
        System.out.println("GetUpdate save..." + id);
        return "{'module':'book save'}";
    }

    @PutMapping
    public String update2(@RequestBody Book book){
        System.out.println("GetUpdate save..." + book);
        return "{'module':'book save'}";
    }




}
